package com.cmc.cloud.cmclink.doc.controller.admin.special;

import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.service.special.EmailTaskService;
import com.cmc.cloud.cmclink.doc.vo.EmailSendTaskBaseVO;
import com.cmc.cloud.cmclink.doc.vo.EmailSendTaskPageReqVO;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import com.cmes.framework.operatelog.core.annotations.OperateLog;
import com.cmes.framework.operatelog.core.enums.OperateTypeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


/**
 * 邮件发送任务单前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 邮件发送任务单")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/emailSendTask")
public class EmailSendTaskController {

    @Resource
    private EmailTaskService emailTaskService;

    @Operation(summary = "取消发送")
    @PostMapping("/cancelSend")
    @OperateLog(name = "取消发送", type = OperateTypeEnum.UPDATE)
    public CommonResult<Void> cancelSend(@RequestBody List<Long> ids) {
        emailTaskService.cancelSend(ids);
        return CommonResult.success();
    }

    @Operation(summary = "更新发送时间间隔")
    @PostMapping("/updateSendInterval")
    @OperateLog(name = "更新发送时间间隔", type = OperateTypeEnum.UPDATE)
    public CommonResult<Void> updateSendInterval(@RequestBody String timeInterval) {
        emailTaskService.updateSendInterval(timeInterval);
        return CommonResult.success();
    }

    @Operation(summary = "更新发送时间间隔")
    @GetMapping("/getSendInterval")
    @OperateLog(name = "更新发送时间间隔", type = OperateTypeEnum.UPDATE)
    public CommonResult<String> getSendInterval() {
        return CommonResult.success(emailTaskService.getSendInterval());
    }

    @Operation(summary = "重新发送")
    @PostMapping("/reSend")
    @OperateLog(name = "重新发送", type = OperateTypeEnum.CREATE)
    public CommonResult<Void> reSend(@RequestBody List<Long> ids) {
        emailTaskService.reSend(ids);
        return CommonResult.success();
    }


    @Operation(summary = "获得邮件发送任务单分页")
    @PostMapping("/page")
    @OperateLog(name = "获得邮件发送任务单分页", type = OperateTypeEnum.GET)
    public CommonResult<PageResult<EmailSendTaskBaseVO>> getEmailSendTaskPage(@RequestBody @Valid EmailSendTaskPageReqVO pageVO) {
        PageResult<EmailSendTaskBaseVO> pageResult = emailTaskService.getEmailSendTaskPage(pageVO);
        return CommonResult.success(pageResult);
    }
}
